<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>家庭医生信息管理系统</title>
    <link rel="icon" type="image/x-icon" href="/images/logo.png">
    <link rel="stylesheet" href="/css/login.css">
</head>
<body>
<div class="wrap">
    <div class="login-box">
        <div class="logo"></div>
        <p class="supplier-name">家庭医生信息管理系统</p>
        <div class="form-box">
            <form class="form" id="loginForm">
                <ul class="login-list">
                    <li class="login-item">
                        <div class="icon-box">
                            <i class="username-icon"></i>
                        </div>
                        <div class="username">
                            <input type="text" name="name" id="username" class="username-input" placeholder="用户名">
                        </div>
                    </li>
                    <li class="tips username-tips">
                        <div class="show-hide-1" style="display: none;">
                            <i class="tips-icon"></i>
                            <span class="tips-txt">用户名不正确！</span>
                        </div>
                    </li>
                    <li class="login-item">
                        <div class="icon-box">
                            <i class="password-icon"></i>
                        </div>
                        <div class="password">
                            <input type="password" name="password" id="password" class="password-input" placeholder="密码">
                        </div>
                    </li>
                    <li class="tips password-tips">
                        <div class="show-hide-2" style="display: none;">
                            <i class="tips-icon"></i>
                            <span class="tips-txt">密码错误！</span>
                        </div>
                    </li>
                    <li class="login-item code-box">
                        <div class="code">
                            <input type="text" name="checCodeInput" id="code" class="code-input" placeholder="验证码">
                        </div>
                        <div class="checkcode">
                            <img id="checkCode" onclick="resetCode(this)" src="/login/getCode" alt="看不清？点击刷新" title="看不清？点击刷新">
                        </div>
                    </li>
                    <li class="tips security-tips">
                        <div class="show-hide-2" style="display: none;">
                            <i class="tips-icon"></i>
                            <span class="tips-txt">验证错误！</span>
                        </div>
                    </li>
                    <li class="login-item">
                        <a onclick="submitForm()" class="login-btn">登录</a>
                    </li>
                    <li class="register-item">
                        <a onclick="registration()" class="register-btn">账号注册</a>
                    </li>
                </ul>
            </form>
        </div>
    </div>
</div>
<script src="/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="/layer/layer.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript">
    document.onkeydown=function(){
        if (event.keyCode == 13){
            submitForm();
        }
    }
    $(document).ready(function() {
        var oWrap = document.querySelector(".wrap");
        var oHeight = document.documentElement.clientHeight;
        var oWidth = document.documentElement.clientWidth;
        oWrap.style.height = oHeight + "px";
        oWrap.style.width = oWidth + "px";

        if(window!=window.top){
            window.top.location.href="/";
        }
    });

    function resetCode(checkCode) {
        checkCode.src = '/login/getCode' + '?id=' + Math.random();
    }

    function submitForm() {
        var name=$('#username').val();
        var password=$('#password').val();
        var code=$('#code').val();
        if (name==''){
            com.msg_error("请输入账号");
            return false;
        }
        if (password==''){
            com.msg_error("请输入密码");
            return false;
        }
        if (code==''){
            com.msg_error("请输入验证码");
            return false;
        }
        var index=com.msg_load();
        $.ajax({
            type: "POST",
            url: "/login/doLogin",
            data:$('#loginForm').serialize(),
            success: function (data) {
                com.msg_load_close(index);
                var d=eval(data);
                if (data!=null&&d.msg=='success') {
                    window.location.href = '/main'
                } else {
                    $("#checkCode").click();
                    com.msg_error(d.msg);
                }
            }
        });
    }

    function registration() {
        location.href="/register"
    }

</script>
</body>
</html>